package com.itcsystem.manager;

import com.itcsystem.connection.ConnectionUtility;
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import com.itcsystem.struct.Instituto;

public class InstitutoManager{
	private ConnectionUtility connectionUtility = ConnectionUtility.getConnectionUtility();

	public Integer insertInstituto(Instituto instituto){
		String sql = "INSERTINSTITUTO ?,?";
	
		List<Object> parameters = new ArrayList<Object>();
		parameters.add(instituto.getNombre());
		connectionUtility.buildPreparedStatement(sql, parameters, true);
		
		return connectionUtility.executeSQLInsert();
	}
	public Boolean deleteInstituto(int idInstituto){
		String sql = "DELETEINSTITUTO ?";
		connectionUtility.buildPreparedStatement(sql, idInstituto);
	
		return connectionUtility.executeSQLDelete();
	}
	public List<Instituto> getInstitutos(){
		List<Instituto> listInstituto = new ArrayList<Instituto>();
		String sql = "SELECTINSTITUTO";
	
		try{
			ResultSet resultSet = connectionUtility.getResult(sql);
		
			if (resultSet !=null){
				while(resultSet.next()){
					Instituto obj = new Instituto();
		
					obj.setNombre((java.lang.String)resultSet.getObject("Nombre"));
	
					obj.setId((int)resultSet.getObject("Id"));
	
					
					listInstituto.add(obj);
				}
			}
		}
		catch(SQLException ex){
			ex.printStackTrace();
		}
	
		return listInstituto;
	}
}
